package vzaar

import scala.collection.mutable.ArrayBuffer
import scala.xml._ 
import scala.xml.path._ 

object User {
	def parse(response:VzaarTransportResponse):User = {
	  var document = XML.load(response.response)
	  new User(
		VzaarUtil.xmlAsString(document, "version"),
		VzaarUtil.xmlAsString(document, "author_name"),
		VzaarUtil.xmlAsString(document, "author_id"),
		VzaarUtil.xmlAsString(document, "author_url"),
		VzaarUtil.xmlAsString(document, "author_account"),
		VzaarUtil.xmlAsString(document, "created_at"),
		VzaarUtil.xmlAsString(document, "video_count"),
		VzaarUtil.xmlAsString(document, "play_count"))
	}  
}

class User(
  val version:String, 
  val authorName:String, val authorId:String, val authorUrl:String, 
  val authorAccount:String, val createdAt:String, 
  val videoCount:String, val playCount:String) {}

object AccountType {
	def parse(response:VzaarTransportResponse):AccountType = {
	  var document = XML.load(response.response)
	  new AccountType(
		VzaarUtil.xmlAsString(document, "version"),
		VzaarUtil.xmlAsString(document, "account_id"),
		VzaarUtil.xmlAsString(document, "title"),
		VzaarUtil.xmlAsString(document, "monthly"),
		VzaarUtil.xmlAsString(document, "currency"),
		VzaarUtil.xmlAsString(document, "bandwidth"),
		VzaarUtil.xmlAsString(document, "borderless"),
		VzaarUtil.xmlAsString(document, "searchEnhancer"))
   }
}
 
class AccountType(
	val version:String, val accountId:String, val title:String, 
	val monthly:String, val currency:String, val bandwidth:String, 
	val borderless:String, val searchEnhancer:String)


class VideoListRequest(var username:String) {
	var count:Int = 100
 	var page:Int = 1
  	var listMinimumOnly:Boolean = false
  	var sortAscending:Boolean = false
    var includeVideoSize:Boolean = true
    var titleSearch:String = null
    
    def asParameters():Map[String,String] = {
      Map(
       "count" -> count.toString, 
       "page" -> page.toString, 
       "list_only" -> listMinimumOnly.toString, 
       "sort" -> sortAscending.toString, 
       "size" -> includeVideoSize.toString,
       "title" -> titleSearch)
    }
}

object Video {
	def parse(response:VzaarTransportResponse):List[Video] = {
		var videoList = new ArrayBuffer[Video]
		var document = XML.load(response.response)
		VzaarUtil.xmlNodes(document, "video").foreach((current:Node) =>
		  	videoList.append(new Video(
				VzaarUtil.xmlAsString(current, "version"),
				VzaarUtil.xmlAsString(current, "id"),
				VzaarUtil.xmlAsString(current, "title"),
				VzaarUtil.xmlAsString(current, "description"),
				VzaarUtil.xmlAsString(current, "created_at"),
				VzaarUtil.xmlAsString(current, "url"),
				VzaarUtil.xmlAsString(current, "thumbnail_url"),
				VzaarUtil.xmlAsString(current, "play_count"),
				VzaarUtil.xmlAsString(current, "author_name"),
				VzaarUtil.xmlAsString(current, "author_url"),
				VzaarUtil.xmlAsString(current, "author_account"),
				VzaarUtil.xmlAsString(current, "video_count"),
				VzaarUtil.xmlAsString(current, "duration"),
				VzaarUtil.xmlAsString(current, "width"),
				VzaarUtil.xmlAsString(current, "height")))
		)
		
		return videoList.toList
	}
}


class Video(
	val version:String, val id:String, val title:String,
	val description:String, val createdAt:String,
	val url:String, val thumbnailUrl:String, val playCount:String,
	val authorName:String, val authorUrl:String, val authorAccount:String,
	val videoCount:String, val duration:String,	val width:String,
	val height:String)


class VideoDetailsRequest(var videoId:String) {
	var maximumWidth:Int = 0
 	var maximumHeight:Int = 0
  	var borderless:Boolean = false
   	var thumbnail:Boolean = true
    var framegrab:Boolean = true
    var embedOnly:Boolean = false
    var duration:Boolean = true
    var description:Boolean = true

    def asParameters():Map[String,String] = {
     Map(
       "maxwidth" -> maximumWidth.toString, 
       "maxheight" -> maximumHeight.toString, 
       "borderless" -> borderless.toString, 
       "thumbnail" -> thumbnail.toString, 
       "framegrab" -> framegrab.toString, 
       "embed_only" -> embedOnly.toString,
       "duration" -> duration.toString,
       "description" -> description.toString)
    }
}

object VideoDetails 
{
	def parse(response:VzaarTransportResponse): VideoDetails = {
	  var document = XML.load(response.response)
	  new VideoDetails(
		VzaarUtil.xmlAsString(document, "type"),
		VzaarUtil.xmlAsString(document, "version"),
		VzaarUtil.xmlAsString(document, "title"),
		VzaarUtil.xmlAsString(document, "description"),
		VzaarUtil.xmlAsString(document, "author_name"),
		VzaarUtil.xmlAsString(document, "author_url"),
		VzaarUtil.xmlAsString(document, "author_account"),
		VzaarUtil.xmlAsString(document, "provider_name"),
		VzaarUtil.xmlAsString(document, "provider_url"),
		VzaarUtil.xmlAsString(document, "thumbnail_url"),
		VzaarUtil.xmlAsString(document, "thumbnail_width"),
		VzaarUtil.xmlAsString(document, "thumbnail_height"),
		VzaarUtil.xmlAsString(document, "framegrab_url"),
		VzaarUtil.xmlAsString(document, "framegrab_width"),
		VzaarUtil.xmlAsString(document, "framegrab_height"),
		VzaarUtil.xmlAsString(document, "html"),
		VzaarUtil.xmlAsString(document, "width"),
		VzaarUtil.xmlAsString(document, "height"),
		VzaarUtil.xmlAsString(document, "borderless"),
		VzaarUtil.xmlAsString(document, "duration"),
		VzaarUtil.xmlAsString(document, "video_status_id"))
   }
}

class VideoDetails(
  val resourceType:String, val version:String, val title:String, 
  val description:String, val authorName:String, val authorUrl:String, 
  val authorAccount:String, val providerName:String, val providerUrl:String, 
  val thumbnailUrl:String, val thumbnailWidth:String, val thumbnailHeight:String, 
  val framegrabUrl:String, val framegrabWidth:String, val framegrabHeight:String, 
  val html:String, val height:String, val width:String, val borderless:String, 
  val duration:String, val videoStatusId:String)

object UploadSignature
{
	def parse(response:VzaarTransportResponse):UploadSignature = {
	  var document = XML.load(response.response)
	  new UploadSignature(
			VzaarUtil.xmlAsString(document, "guid"),
			VzaarUtil.xmlAsString(document, "key"),
			VzaarUtil.xmlAsString(document, "https"),
			VzaarUtil.xmlAsString(document, "acl"),
			VzaarUtil.xmlAsString(document, "bucket"),
			VzaarUtil.xmlAsString(document, "policy"),
			VzaarUtil.xmlAsString(document, "expirationdate"),
			VzaarUtil.xmlAsString(document, "accesskeyid"),
			VzaarUtil.xmlAsString(document, "signature"))
   }
}

class UploadSignature(
	val guid:String, val key:String, val https:String,
	val acl:String, val bucket:String, val policy:String,
	val expirationDate:String, val accessKeyId:String, val signature:String)

